<?php
namespace Popshouse\SiteBundle\Entity;


/**
*
*/
class Price{
	
	public function __construct(){
		$this->load();
	}

	/**
     * @assert:NotBlank
     * @assert:Type("numeric")
     */
	protected $base;

	/**
     * @assert:NotBlank
     * @assert:Type("numeric")
     */
	protected $single;

	/**
     * @assert:NotBlank
     * @assert:Type("numeric")
     */
	protected $third;
	
	/**
     * @assert:NotBlank
     * @assert:Type("numeric")
     */
	protected $fourth;
	
	/**
     * @assert:NotBlank
     * @assert:Type("numeric")
     * @assert:Min(0)
     * @assert:Max(100)
     */
	protected $short;
	
	/**
     * @assert:NotBlank
     * @assert:Type("numeric")
     * @assert:Min(0)
     * @assert:Max(100)
     */
	protected $long;


	/**
	 * @return the $base
	 */
	public function getBase() {
		return $this->base;
	}

	/**
	 * @return the $single
	 */
	public function getSingle() {
		return $this->single;
	}

	/**
	 * @return the $third
	 */
	public function getThird() {
		return $this->third;
	}

	/**
	 * @return the $fourth
	 */
	public function getFourth() {
		return $this->fourth;
	}

	/**
	 * @return the $short
	 */
	public function getShort() {
		return $this->short;
	}

	/**
	 * @return the $long
	 */
	public function getLong() {
		return $this->long;
	}

	/**
	 * @param field_type $base
	 */
	public function setBase($base) {
		$this->base = (int) $base;
	}

	/**
	 * @param field_type $single
	 */
	public function setSingle($single) {
		$this->single = (int) $single;
	}

	/**
	 * @param field_type $third
	 */
	public function setThird($third) {
		$this->third = (int) $third;
	}

	/**
	 * @param field_type $fourth
	 */
	public function setFourth($fourth) {
		$this->fourth = (int) $fourth;
	}

	/**
	 * @param field_type $short
	 */
	public function setShort($short) {
		$this->short = (int) $short;
	}

	/**
	 * @param field_type $long
	 */
	public function setLong($long) {
		$this->long = (int) $long;
	}

	public function save(){
		//$dom = new \DOMDocument();
		$string = '<?xml version="1.0"?><pricing></pricing>';
		$prices = new \SimpleXMLElement($string);
		$prices->addChild('base',$this->getBase());
		$prices->addChild('single',$this->getSingle());
		$prices->addChild('third',$this->getThird());
		$prices->addChild('fourth',$this->getFourth());
		$prices->addChild('short',$this->getShort());
		$prices->addChild('long',$this->getLong());
		//die($prices->asXML());
		$prices->asXML($this->getFileName());
	}
	
	public function load(){

		$xml = simplexml_load_file($this->getFileName());
		$this->setBase($xml->base);
		$this->setThird($xml->third);
		$this->setFourth($xml->fourth);
		$this->setSingle($xml->single);
		$this->setShort($xml->short);
		$this->setLong($xml->long);
		
	}
	
	private function getFileName(){
		return __DIR__.'/pricing.xml';
		
	}
}
 
